package cn.sunshine.framework.beans;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description cn.sunshine.framework.beans
 * @Author Mokairui
 * @Since 2021/12/11
 */
public class PropertyValues {

    private List<PropertyValue> propertyValueList = new ArrayList<>();

    public void addPropertyValue(PropertyValue pv) {
        propertyValueList.add(pv);
    }

    public PropertyValue[] getPropertyValues() {
        return this.propertyValueList.toArray(new PropertyValue[0]);
    }

    public PropertyValue getPropertyValue(String propertyName) {
        // stream 流获取
//        this.propertyValueList.stream().filter(pv -> pv.getName().equals(propertyName)).findFirst().orElseGet(null);
        // 传统方式
        for (PropertyValue pv : this.propertyValueList) {
            if (pv.getName().equals(propertyName)) {
                return pv;
            }
        }
        return null;
    }

}
